#include <bits/stdc++.h>

using namespace std;

const int N = 10;
int n;
bool st[N];
int path[N];

void dfs(int num)
{
    if (num > n)
    {
        for (int i = 1; i <= n; ++i)
        {
            cout << path[i] << " ";
        }
        cout << endl;
        return;
    }
    for (int i = 1; i <= n; ++i)
    {
        if (!st[i])
        {
            path[num] = i;
            st[i] = true;
            dfs(num + 1);
            st[i] = false;
        }
    }
}

int main()
{
    cin >> n;
    dfs(1);
    return 0;
}
